Soru & Cevap

2 aktivite arasa son skoru paylaşma

09.12.2017 - 07:50

Merhaba iyi günler.Ben 2 aktivite arası bilgi aktaramı yapmak istiyorum.2 gündür uğraşıyorum(acemi seviyedeyim mazur görün)beceremedim.Intet denedim yapamadım textView ile almayı denedim olmuyor.Cevabı verecek kişi cevabı kırmızı harflerle yazarsa hatamı anlayabilirim.

 

Görsel kaldırıldı.

  • BİRİNCİ AKTİVİTE
package com.taylansular.bluebird;

import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.Random;

public class MainActivity extends AppCompatActivity {
    public final static String EXTRA_MESSAGE = "skor";

    TextView scoreText;
    TextView timeText;
    ImageView imageView1;
    ImageView imageView2;
    ImageView imageView3;
    ImageView imageView4;
    ImageView imageView5;
    ImageView imageView6;
    ImageView imageView7;
    ImageView imageView8;
    ImageView imageView9;
    ImageView imageView10;
    ImageView imageView11;
    ImageView imageView12;
    ImageView imageView13;
    ImageView imageView14;
    ImageView imageView15;
    ImageView imageView16;
    int score;
    ImageView [] imageArray;
    Handler handler;
    Runnable runnable;
    Bundle bundle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        imageView1 = (ImageView) findViewById(R.id.imageView);
        imageView2 = (ImageView) findViewById(R.id.imageView2);
        imageView3 = (ImageView) findViewById(R.id.imageView3);
        imageView4 = (ImageView) findViewById(R.id.imageView4);
        imageView5 = (ImageView) findViewById(R.id.imageView5);
        imageView6 = (ImageView) findViewById(R.id.imageView6);
        imageView7 = (ImageView) findViewById(R.id.imageView7);
        imageView8 = (ImageView) findViewById(R.id.imageView8);
        imageView9 = (ImageView) findViewById(R.id.imageView9);
        imageView10 = (ImageView) findViewById(R.id.imageView10);
        imageView11= (ImageView) findViewById(R.id.imageView11);
        imageView12= (ImageView) findViewById(R.id.imageView12);
        imageView13= (ImageView) findViewById(R.id.imageView13);
        imageView14 = (ImageView) findViewById(R.id.imageView14);
        imageView15= (ImageView) findViewById(R.id.imageView15);
        imageView16= (ImageView) findViewById(R.id.imageView16);
        imageArray = new ImageView[]{imageView1, imageView2,imageView3, imageView4,imageView5, imageView6,imageView7, imageView8,imageView9, imageView10,imageView11, imageView12,imageView13, imageView14,imageView15, imageView16};

        hideImages();

        score = 0;


        CountDownTimer start = new CountDownTimer(10000, 1000) {


            @Override
            public void onTick(long millisUntilFinished) {
                timeText = (TextView) findViewById(R.id.textTime);
                timeText.setText("Time : " + millisUntilFinished / 1000);
            }

            @Override
            public void onFinish() {
                timeText = (TextView) findViewById(R.id.textTime);
                timeText.setText("Time is up ! ");
                handler.removeCallbacks(runnable);

                for (ImageView image : imageArray) {
                    image.setVisibility(View.INVISIBLE);
                }
                int x = 0;
                if (score < 10){
                    Intent intent = new Intent(MainActivity.this, Main2Activity.class);
                    MainActivity.this.startActivity(intent);

                }
                else if (score > 10){

                    Intent intent = new Intent(MainActivity.this, Main3Activity.class);
                    MainActivity.this.startActivity(intent);

                }


            }

        }.start();




        }

        public void skoruArttır(View view){

        scoreText = (TextView) findViewById(R.id.textScore);

        score++;

        scoreText.setText("Score " + score);


    }





    public void hideImages(){
        handler = new Handler();
        runnable = new Runnable(){

            @Override
            public void run() {
                for (ImageView image : imageArray){
                    image.setVisibility(View.INVISIBLE);

                }

                Random r = new Random();
                int i = r.nextInt(15-0);
                imageArray[i].setVisibility(View.VISIBLE);

                handler.postDelayed(this, 1000);
            }
        };


        handler.post(runnable);
    }



}

------------------------------------------------------------------------

  • İKİNCİ AKTİVİTE 

  

  

package com.taylansular.bluebird;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Main2Activity extends AppCompatActivity {

    TextView textView;
    int score;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        TextView textView = (TextView) findViewById(R.id.seninskorun);


        Button yenidenbasla = (Button) findViewById(R.id.yenidenbasla);

        yenidenbasla.setOnClickListener(
                new Button.OnClickListener() {
                    public void onClick(View view) {
                        Intent ıntent = new Intent(Main2Activity.this, MainActivity.class);
                        startActivity(ıntent);
                    }
                }
        );






    }




}

 

37 Görüntülenme

2 Cevap

Sitedeki sorulara cevap verebilmek için giriş yapın ya da üye olun.

picture-33971-1512978248.png
SezginÖzdemir
11.12.2017 - 10:43

Ek olarak , HighScore tarzı misal en yüksek 10 skoru tutma gibi bi amacın varsa eğer SharedPreferences kullanımını araştırman faydalı olabilir. SharedPreferences basit şekilde bilgileri hafızada tutmana fayda sağlar.

Profile picture for user dclmrl
dclmrl
10.12.2017 - 12:37
https://www.kodcuherif.com/android-sayfalar-arasi-veri-tasima.html Bu link işinizi görecektir. Kolay gelsin